package com.yunzheng.studyLeaveSystem.modules.user.adjust.adjust.servlet; /**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/01/28/19:34
 * @Description:
 */

import com.alibaba.fastjson.JSON;
import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import com.yunzheng.studyLeaveSystem.modules.user.adjust.adjust.entity.Adjust;
import com.yunzheng.studyLeaveSystem.modules.user.adjust.adjust.service.AdjustService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

/*
 *将调研学信息放入数据库
 */
@WebServlet(name = "AdjustServlet", value = "/AdjustServlet")
public class AdjustServlet extends HttpServlet {
    private AdjustService adjustService = new AdjustService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("id",7);
        int  id = (int)session.getAttribute("id");
        //获取请求体数据
        BufferedReader reader = request.getReader();
        String readLine = reader.readLine();
        //将JSON字符转化为JAVA对象
        Adjust adjust = JSON.parseObject(readLine, Adjust.class);
        try {
            adjustService.adjust(adjust,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        ResponseWrapper responseWrapper = ResponseWrapper.SuccessButNoData();
        String s = JSON.toJSONString(responseWrapper);
        PrintWriter writer = response.getWriter();
        writer.println(s);
        System.out.println(s);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     doGet(request, response);
    }
}
